package com.example.demo.component;

import com.example.demo.configuration.BeanUserInfo;
import com.example.demo.configuration.UserInfo;
import com.example.demo.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

@Component
public class UserComponent {
    @Autowired
    public UserService service;
    // userInfo 和 Bean同名,就可以直接拿
//    @Autowired
//    public UserInfo userInfo;

    // 2. 可以实在 Primry 这是默认的, 在设置Bean的时候

    //3. 使用@Qualifier
//
//    @Qualifier("userInfo2")
//    @Autowired
//    public UserInfo userInfo;

    @Resource(name = "userInfo2")
    public UserInfo userInfo;


    public void doComponent() {
        service.doService();
        System.out.println(userInfo.toString());
        System.out.println("do component...");
    }
}
